using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Http;

namespace RAG.Application.Dtos;

/// <summary>
/// 生成答案DTO
/// </summary>
public class GenerateAnswerDto
{
    [Required(ErrorMessage = "用户ID不能为空")]
    public Guid UserId { get; set; }
    
    [Required(ErrorMessage = "问题不能为空")]
    public string Question { get; set; } = null!;
    
    public Guid? KnowledgeBaseId { get; set; }
    
    public Guid? SessionId { get; set; }
    
    [StringLength(100, ErrorMessage = "模型名称长度不能超过100个字符")]
    public string Model { get; set; } = "gpt-3.5-turbo";
    
    public int MaxTokens { get; set; } = 1000;
    
    public double Temperature { get; set; } = 0.7;

    public string? XunfeiVersion { get; set; } // v1/v2
    public string? XunfeiMode { get; set; } // chat/reasoner
    public string? DeepseekMode { get; set; } // chat/reasoner
}

/// <summary>
/// 创建会话DTO
/// </summary>
public class CreateSessionDto
{
    [Required(ErrorMessage = "用户ID不能为空")]
    public Guid UserId { get; set; }
    
    [Required(ErrorMessage = "会话标题不能为空")]
    [StringLength(200, ErrorMessage = "会话标题长度不能超过200个字符")]
    public string SessionTitle { get; set; } = null!;
    
    public Guid? KnowledgeBaseId { get; set; }
    
    public string? Metadata { get; set; }
}

/// <summary>
/// 更新会话DTO
/// </summary>
public class UpdateSessionDto
{
    [Required(ErrorMessage = "会话ID不能为空")]
    public Guid SessionId { get; set; }

    [Required(ErrorMessage = "用户ID不能为空")]
    public Guid UserId { get; set; }

    [StringLength(200, ErrorMessage = "会话标题长度不能超过200个字符")]
    public string? SessionTitle { get; set; }

    [StringLength(50, ErrorMessage = "会话状态长度不能超过50个字符")]
    public string? SessionStatus { get; set; } // active/closed 等

    public string? Metadata { get; set; }
}

/// <summary>
/// 发送消息DTO
/// </summary>
public class SendMessageDto
{
    [Required(ErrorMessage = "会话ID不能为空")]
    public Guid SessionId { get; set; }
    
    [Required(ErrorMessage = "用户ID不能为空")]
    public Guid UserId { get; set; }
    
    [Required(ErrorMessage = "消息内容不能为空")]
    public string Message { get; set; } = null!;
    
    public Guid? KnowledgeBaseId { get; set; }
    
    [StringLength(100, ErrorMessage = "模型名称长度不能超过100个字符")]
    public string Model { get; set; } = "deepseek-chat";
    
    public int MaxTokens { get; set; } = 1000;
    
    public double Temperature { get; set; } = 0.7;

    public string? XunfeiVersion { get; set; } // v1/v2
    public string? XunfeiMode { get; set; } // chat/reasoner
    public string? DeepseekMode { get; set; } // chat/reasoner
}

/// <summary>
/// 搜索文档DTO
/// </summary>
public class SearchDocumentsDto
{
    [Required(ErrorMessage = "用户ID不能为空")]
    public Guid UserId { get; set; }
    
    public string? Keyword { get; set; }
    
    public Guid? KnowledgeBaseId { get; set; }
    
    public string? DocumentType { get; set; }
    
    public string? Status { get; set; }
    
    public int Page { get; set; } = 1;
    
    public int PageSize { get; set; } = 10;
}

/// <summary>
/// 批量上传文档DTO
/// </summary>
public class BatchUploadDocumentsDto
{
    [Required(ErrorMessage = "用户ID不能为空")]
    public Guid UserId { get; set; }
    
    [Required(ErrorMessage = "知识库ID不能为空")]
    public Guid KnowledgeBaseId { get; set; }
    
    [Required(ErrorMessage = "文件列表不能为空")]
    public List<IFormFile> Files { get; set; } = new();
    
    public string? DocumentAccessLevel { get; set; } = "private";
}

/// <summary>
/// 更新文档DTO
/// </summary>
public class UpdateDocumentDto
{
    [Required(ErrorMessage = "文档ID不能为空")]
    public Guid DocumentId { get; set; }
    
    [Required(ErrorMessage = "用户ID不能为空")]
    public Guid UserId { get; set; }
    
    [Required(ErrorMessage = "文档标题不能为空")]
    [StringLength(200, ErrorMessage = "文档标题长度不能超过200个字符")]
    public string DocumentTitle { get; set; } = null!;
}

/// <summary>
/// 文档权限设置DTO
/// </summary>
public class UpdateDocumentPermissionsDto
{
    [Required(ErrorMessage = "文档ID不能为空")]
    public Guid DocumentId { get; set; }
    
    [Required(ErrorMessage = "用户ID不能为空")]
    public Guid UserId { get; set; }
    
    [Required(ErrorMessage = "访问级别不能为空")]
    public string DocumentAccessLevel { get; set; } = "private"; // private, public, shared
}

/// <summary>
/// 系统统计DTO
/// </summary>
public class SystemStatisticsDto
{
    public int TotalUsers { get; set; }
    public int ActiveUsers { get; set; }
    public int TotalDocuments { get; set; }
    public int TotalConversations { get; set; }
    public int TotalKnowledgeBases { get; set; }
    public long TotalStorageUsed { get; set; }
    public Dictionary<string, int> DocumentStatusCounts { get; set; } = new();
    public Dictionary<string, int> ConversationModelCounts { get; set; } = new();
}

/// <summary>
/// 用户对话记录查询DTO
/// </summary>
public class GetUserConversationsDto
{
    [Required(ErrorMessage = "用户ID不能为空")]
    public Guid UserId { get; set; }
    
    public DateTime? StartDate { get; set; }
    public DateTime? EndDate { get; set; }
    public string? Model { get; set; }
    public int Page { get; set; } = 1;
    public int PageSize { get; set; } = 20;
}


